import { typeOf } from './assist'
export default class QueryString {
    constructor() {
        // super()
    }
    static stringify(data) {
        if (typeOf(data) !== 'object') return;
        const arr = [];
        const converObj = function (obj, prefix) {
            const type = typeOf(obj);
            if (type === 'object') {
                Object.keys(obj).forEach(function (key) {
                    converObj(this[key], prefix ? `${prefix}[${key}]` : key)
                }, obj)
            } else if (type === 'array') {
                Object.keys(obj).forEach(function (key) {
                    converObj(this[key], prefix)
                }, obj)
            } else {
                if(obj===undefined||obj===null) obj="";
                arr.push(`${prefix}=${obj}`);
            }
        };
        converObj(data);
        return arr.join('&');
    }
}